<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 450px;
            height: 350px;
            border: 1px solid gray;
            margin: 100px auto;
            /* border-radius: 10px; */
            padding-top: 10px;
            border-radius: 20px;
        }
        input{
            width: 350px;
            height: 35px;
            margin-left: 50%;
            transform: translateX(-50%);
            border-radius: 10px;
            border: 1px solid gray;
            border-radius: 10px;
            
        }
        button{
            width: 350px;
            height: 35px;
            margin-left: 50%;
            transform: translateX(-50%);
            color: white;
            background-color: rgb(80, 80, 245);
            border: 0;
            margin-top: 30px;
            border-radius: 10px;
            transition: all 1s;
        }
        button:hover{
            
            background-color: rgb(114, 114, 253);
        }
        .kuang{
            margin-top: 20px;
        }
        p{
            text-align: center;
            font-weight: 800;
            font-size: 22px;
        }

    </style>
</head>

<body>
    <div class="box">
        <p>注册</p>
        <div class="kuang">
            <input type="text" placeholder="手机号">
        </div>
        <div class="kuang" >
            <input type="password" placeholder="密码">
        </div>
        <div class="kuang" >
            <input type="password" placeholder="确认密码">
        </div>
        <button>注册</button>
    </div>

</body>

</html>
<script src="./ajax.js"></script>
<script>
    inps = document.querySelectorAll('input')
    btn = document.querySelector('button')
    // console.log(inps);
    btn.onclick = function () {
        // 判断是否为空
        if (inps[0].value && inps[1].value && inps[2].value) {
            // 判断手机号和密码格式
            if (/^1[3-9]\d{9}$/.test(inps[0].value) && /^\d{4}$/.test(inps[1].value)) {
                if (inps[1].value == inps[2].value) {
                    ajax('get', 'https://yantianfeng.com/api/register', { username: inps[0].value, password: inps[1].value }, function (data) {
                        console.log(data)
                    })
                }
                else {
                    alert('两次密码输入不一致')
                }

            }
            else {
                alert('手机号/密码格式不正确')
            }
        }
        else {
            alert('手机号和密码不能为空')
        }

    }

</script>